/**
 * Efficient linked list implementation:
 *     size   - O(1)
 *     add    - O(1)
 *     remove - O(1)
 *     
 * @author Gadi Elishayov - 026540005
 * @author Ruby Fienstein - 310211074
 */
public class RealLinkedList {
	
	public int size() {
		return size;
	}
	
	public LinkedItem head() {
		return head;
	}
	
	public void add(LinkedItem le) {
		if (head == null) {
			le.prev = le.next = null;
			head = le;
		} else {
			le.next = head;
			head.prev = le;
			head = le;
		}
		++size;
	}
	
	public void remove(LinkedItem le) {
		if (head == le) {
			head = head.next;
			le.prev = le.next = null;
		} else {
			le.prev.next = le.next;
			if (le.next != null) {
				le.next.prev = le.prev;
			}
			le.prev = le.next = null;
		}
		--size;
	}
	
	private int size = 0;
	private LinkedItem head = null;
}
